// https://leetcode.cn/problems/symmetric-tree/


#include <iostream>
#include <vector>


using namespace std;

struct TreeNode {
    int val;
    TreeNode *left;
    TreeNode *right;

    TreeNode() : val(0), left(nullptr), right(nullptr) {}

    TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}

    TreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left), right(right) {}
};

class Solution {
public:
    bool flag = true;
    bool isSymmetric(TreeNode *root) {
        compare(root->left, root->right);
        return flag;
    }

    void compare(TreeNode *left, TreeNode * right) {
        if(!left && right || left && !right) {
            flag = false;
            return;
        }
        if(left && right){
            if(left->val != right->val) {
                flag = false;
                return;
            }
            compare(left->left, right->right);
            compare(left->right, right->left);
        }
    }

    TreeNode *init() {
        TreeNode *n1 = new TreeNode(1);
        TreeNode *n2 = new TreeNode(2);
        TreeNode *n3 = new TreeNode(2);
        TreeNode *n4 = new TreeNode(2);
        TreeNode *n5 = new TreeNode(2);
        n1->left = n2;
        n1->right = n3;
        n2->left = n4;
        n3->left = n5;

        return n1;
    }
};

int main() {
    Solution so;
    TreeNode *h1 = so.init();
    if (so.isSymmetric(h1)) {
        cout << "yes" << endl;
    } else {
        cout << "no" << endl;
    }
    return 0;
}